package com.allen.retrofit2_rxjava2.view.selectimageview;

import com.allen.retrofit2_rxjava2.R;
import com.allen.retrofit2_rxjava2.base.TitleViewActivity;
import com.allen.retrofit2_rxjava2.view.selectimageview.utils.CheckImageLoaderConfiguration;
import com.allen.retrofit2_rxjava2.view.selectimageview.utils.CropUtil;
import com.allen.retrofit2_rxjava2.view.selectimageview.utils.UniversalImageLoadTool;
import com.allen.retrofit2_rxjava2.view.selectimageview.view.CropImageView;
import com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;

import butterknife.BindView;

/**
 * 剪裁
 *
 * @author 作者： Administrator
 * @version 创建时间：2014年9月2日下午1:08:06
 */
public class CropImageActivity extends TitleViewActivity {
    @BindView(R.id.cropImg)
    CropImageView cropImageView;

    private String path;

    @Override
    public void init() {
        setContentView(R.layout.activity_cropimage);
        initTitleBar();
        path = getIntent().getStringExtra("PATH");
    }

    Intent intent;
    Message msg;

    private void initTitleBar() {
        initTitleView();
        initLeftBackView(null);
        setCenterViewContent(getResources().getString(R.string.photo));
        initRightView(getResources().getString(R.string.affirm));
        setRightViewOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                CropUtil.saveBitmap2Crop(cropImageView.getCropImage());
                setResult(RESULT_OK);
                finish();
            }
        });
    }

    @Override
    protected void onStart() {
        super.onStart();
        CheckImageLoaderConfiguration.checkImageLoaderConfiguration(this);
        UniversalImageLoadTool.loadImage(path,
                new SimpleImageLoadingListener() {
                    @Override
                    public void onLoadingComplete(String imageUri, View view,
                                                  Bitmap loadedImage) {
                        super.onLoadingComplete(imageUri, view, loadedImage);
                        cropImageView.setDrawable(new BitmapDrawable(
                                getResources(), loadedImage), 100, 100);
                    }
                });
    }

}
